from typing import List, Union

from pydantic import BaseModel


class ItemBase(BaseModel):
    title: str
    description: Union[str, None] = None


class ItemCreate(ItemBase):
    pass


class Item(ItemBase):
    id: int
    owner_id: int

    # orm_mode：将告诉 Pydantic*模型*读取数据，它不是一个dict，而是一个 ORM 模型（或任何其他具有属性的任意对象）
    class Config:
        # orm_mode = True
        from_attributes = True


class UserBase(BaseModel):
    email: str


class UserCreate(UserBase):
    password: str


class User(UserBase):
    id: int
    is_active: bool
    items: List[Item] = []

    class Config:
        # orm_mode = True
        from_attributes = True
